<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>12冒泡排序</title>
	<script>
		var arr = [20,133,65,68,24,15,66,58,100,10];

		for(var i=0;i<arr.length-1;i++){
			console.log(i,'-------------------');
			for(var j=0;j<arr.length-i-1;j++){

				if(arr[j] > arr[j+1]){
					var temp = arr[j];
					arr[j] = arr[j+1];
					arr[j+1] = temp;
				}
				console.log(arr.join());
			}
		}

		console.log(arr);


		// 用数组sort方法实现排序
		var arr = [20,133,65,68,24,15,66,58,100,10];
		arr.sort(function(a,b){
			// console.log(a,b);
			
			/*if(a>b){
				return 1;
			}else if(a < b){
				return -1;
			}else{
				return 0;
			}*/

			return a-b;
		});

		console.log(arr);
		console.log(arr.reverse());
	</script>
</head>
<body>
	
</body>
</html>